//
//  OASearchBuMenVC.m
//  OA项目
//
//  Created by innofive on 2018/4/24.
//  Copyright © 2018年 inno. All rights reserved.
//
#import "OAAddressBookHeaderView.h"
#import "OASearchBuMenVC.h"
#import "QKSearchBar.h"
@interface OASearchBuMenVC ()<UISearchBarDelegate>
@property (nonatomic, strong) UITextField * textF;
@property (nonatomic, strong) QKSearchBar * searchBar;
@end

@implementation OASearchBuMenVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}



-(void)onLoadViewByWillAppear:(UIView *)view
{
    
    QKSearchBar *searchBar = [[QKSearchBar alloc]init];
    searchBar.placeholder = @"搜索";
    searchBar.delegate = self;
    [view addV:searchBar];
    
    [self.tableView config:^(UITableView *tableView) {
        [view addV:tableView];
    }];
    
    
    WSELF(weakSelf);
    [self onMainQueueAddSub:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        
        searchBar.frame = CGRectMake(0, 0, size.width,kFitH(45));
        weakSelf.tableView.frame = CGRectMake(0,kFitH(45), size.width, size.height-kFitH(45));
    }];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section ==0) {
        return 0;
    }
    return 10;
}


-(MCCellInfo *)tableView:(UITableView *)tableView cellForIndexPath:(NSIndexPath *)indexPath IsHeight:(BOOL)isheight
{
 return [MCCellInfo configForCellId:cell Class:[OAAddressBookCell class] Height:kFitH(60) TableView:tableView CellStyle:(UITableViewCellStyleValue1)];
    
}

-(void)onCancel:(UIButton *)button
{
    
    [_searchBar setShowsCancelButton:NO animated:YES];
    [_textF resignFirstResponder];
    
}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    [searchBar setShowsCancelButton:YES animated:YES];
    NSArray *subViews;
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        subViews = [(searchBar.subviews[0]) subviews];
    }
    else {
        subViews = searchBar.subviews;
    }
    
    
    for (id view in subViews) {
        
        if (!_textF) {
            
            if ([view isKindOfClass:[UITextField class]]) {
                _textF = view;
            }
        }
        Class class = NSClassFromString(@"UINavigationButton");
        if ([view isKindOfClass:class]) {
            UIButton* cancelbutton = (UIButton* )view;
            [cancelbutton setTitle:@"取消" forState:UIControlStateNormal];
            // 修改文字颜色
            [cancelbutton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [cancelbutton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
            [cancelbutton AddTarget:self Action:@selector(onCancel:)];
        }
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
